package com.dyw.ycgovfinance.mvp.home;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.dyw.ycgovfinance.R;
import com.dyw.ycgovfinance.adapter.MyFragmentPagerAdapter;
import com.dyw.ycgovfinance.mvp.base.BaseActivity;
import com.dyw.ycgovfinance.mvp.me.FragmentMeHome;
import com.dyw.ycgovfinance.mvp.news.newshome.FragmentNewsHome;
import com.dyw.ycgovfinance.mvp.open.FragmentOpenMainView;
import com.dyw.ycgovfinance.mvp.service.FragmentServiceHome;
import com.dyw.ycgovfinance.widget.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/20.
 */

public class ActivityHome extends BaseActivity {

    private RadioGroup rgBottomTab;
    private RadioButton rbIndex;
    private RadioButton rbPublic;


    private RadioButton rbService;
    private RadioButton rbMe;
    private NoScrollViewPager vpMain;


    private List<Fragment> fragments = new ArrayList<>();
    MyFragmentPagerAdapter mFragmentPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        initData();
        assignView();
        initView();
    }

    @Override
    public void initData() {

    }

    @Override
    public void assignView() {
        rgBottomTab = (RadioGroup) findViewById(R.id.rg_bottom_tab);
        rbIndex = (RadioButton) findViewById(R.id.rb_index);
        rbPublic = (RadioButton) findViewById(R.id.rb_public);
        rbService = (RadioButton) findViewById(R.id.rb_service);
        rbMe = (RadioButton) findViewById(R.id.rb_me);
        vpMain = (NoScrollViewPager) findViewById(R.id.vp_main);
    }

    @Override
    public void initView() {
        fragments.add(FragmentNewsHome.newInstance());
        //fragments.add(FragmentInfoHome.newInstance());
        fragments.add(FragmentOpenMainView.newInstance());

        fragments.add(FragmentServiceHome.newInstance());
        fragments.add(FragmentMeHome.newInstance());

        vpMain.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), fragments));
        vpMain.setOffscreenPageLimit(3);
        vpMain.setCurrentItem(0);
//        vpMain.setOffscreenPageLimit(3);
        rgBottomTab.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb_index:
                        vpMain.setCurrentItem(0);
                        break;
                    case R.id.rb_public:
                        vpMain.setCurrentItem(1);
                        break;
                    case R.id.rb_service:
                        vpMain.setCurrentItem(2);
                        break;
                    case R.id.rb_me:
                        vpMain.setCurrentItem(3);
                        break;
                }
            }
        });
    }
}
